package com.zis.auction.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zis.auction.dao.AuctBrowHistDao;
import com.zis.auction.model.AuctBrowhist;
import com.zis.auction.service.IAuctBrowhistInter;
import com.zis.base.impl.BaseInterImpl;
import com.zis.core.Constant;
import com.zis.core.ResponseEntity;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Create by wangshen 2018/1/2
 */
@Service
@Transactional("txManager")
public class AuctBrowhistInterImpl extends BaseInterImpl<AuctBrowhist> implements IAuctBrowhistInter {

    @Autowired
    private SQLManager sqlManager;

    @Autowired
    private AuctBrowHistDao auctBrowHistDao;

    @Override
    public String insert(AuctBrowhist auctBrowhist) throws Exception {
        int num = sqlManager.insert(auctBrowhist);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public String update(AuctBrowhist auctBrowhist) throws Exception {
        return null;
    }

    @Override
    public String delete(String id) throws Exception {
        return null;
    }

    @Override
    public AuctBrowhist selectById(String id) throws Exception {
        return null;
    }

    @Override
    public List<AuctBrowhist> findByCondition(AuctBrowhist auctBrowhist) throws Exception {
        return sqlManager.template(auctBrowhist);
    }

    @Override
    public String findByAusId(String ausId, Integer page, Integer pageSize) throws Exception {
        List<AuctBrowhist> browList = auctBrowHistDao.findByAusId(ausId, page, pageSize);
        if (browList!=null&&browList.size()>0) {
            JSONObject result = new JSONObject();
            result.put("data", browList);
            result.put("page", page);
            result.put("pageSize", pageSize);
            return ResponseEntity.createNormalJsonResponse(result);
        }
        return ResponseEntity.createNULLJsonResponse("未查询到相关数据");
    }
}
